-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(remix-react): export react-router-dom
's useMatch
hook
#5257
Conversation
🦋 Changeset detectedLatest commit: ad9afdb The changes in this PR will be included in the next version bump. This PR includes changesets to release 18 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Hi @nicksrandall, Welcome, and thank you for contributing to Remix! Before we consider your pull request, we ask that you sign our Contributor License Agreement (CLA). We require this only once. You may review the CLA and sign it by adding your name to contributors.yml. Once the CLA is signed, the If you have already signed the CLA and received this response in error, or if you have any questions, please contact us at [email protected]. Thanks! - The Remix team |
Thank you for signing the Contributor License Agreement. Let's get this merged! 🥳 |
useMatch
from "react-router-dom"react-router-dom
's useMatch
hook
I'll note that I can import |
We probably want to wrap export function useMatch<
ParamKey extends ParamParseKey<Path>,
Path extends string
>(pattern: PathPattern<Path> | Path): PathMatch<ParamKey> | null {
let matches = useMatches();
let location = useLocation();
return React.useMemo(() => {
let match = matchPath(pattern, location.pathname); // from react-router
let found = matches.find((m) => m.pathname === match?.pathname);
if (!found || !match) return null;
return {
...match,
...found,
};
}, [matches, pattern, location.pathname]);
} |
@chaance Would you accept this PR if it included the change you mentioned? The big reason that I need this is that I don't want to depend on "react-router-dom" or "react-router" directly. I just want to be able to import from "@remix-run/react"; With the change above I still have to add a new dependency because |
Hang tight on making those changes for now. Let me run this by the team and get some input to make sure it's something we want to expose (and that my implementation makes sense). I understand your concern, but there's no issue with doing what you're doing in the mean time as the React Router dependency isn't going away. |
I think this is fine to re-export directly since we don't want different. behavior for the same hook in RR versus Remix. Since RR has This also came up recently in Discord and we "probably just missed the re-export" per Ryan |
Co-authored-by: Matt Brophy <[email protected]>
🤖 Hello there, We just published version Thanks! |
🤖 Hello there, We just published version Thanks! |
This is useful if you need to give a component some added functionality if a specific path is "active" or not.